package com.matrix.rabbitmqtest.deadqueue;

import cn.hutool.core.lang.Console;
import com.matrix.rabbitmqtest.util.AppKeys;
import com.matrix.rabbitmqtest.util.RabbitMQUtil;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;

/**
 * 死信队列
 * 生产者
 */
public class OrderProducer {
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtil.getChannel();
        channel.exchangeDeclare(AppKeys.NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);
        // 准备发布参数
        AMQP.BasicProperties props = new AMQP.BasicProperties().builder()
                .expiration("10000")
                .build();
        while (true) {
            String orderId = "order_" + Console.input(); // 输入订单号
            channel.basicPublish(AppKeys.NORMAL_EXCHANGE, "order", props, orderId.getBytes(StandardCharsets.UTF_8));
        }
    }
}
